#include "logger.h"
#include <QDir>
#include <QFileInfo>
#include <QDateTime>
#include <QtDebug>

Logger::Logger(QObject *parent) :
    QObject(parent)
{
    QString logpath =  QDir::home().filePath("MindReminder.log");
    QFileInfo fi(logpath);
    QDir dir(fi.absoluteDir());
    fi.setFile( dir, "MindReminder.log" );
    file.setFileName(fi.absoluteFilePath());
}

void Logger::writeLog(const QString &details)
{

         if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)){
             qDebug() << "Can not open log file: " << file.fileName();
             return;
         }

    QString log_details = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");

    QTextStream out(&file);
    out << log_details << "- " << details << "\n";
    file.close();
}
